package com.ck.javacode.Chapter7;

/**
 * @author: caoke
 * @date: 2021/10/18 9:41 上午
 * @description: 重载
 */
public class D7_OverLoad {
    public static void main(String[] args) {
        /*
         * 1) calculate(int n1, int n2) //两个整数的和
         * 2) calculate(int n1, double n2) //一个整数，一个 double 的和
         * 3) calculate(double n2, int n1)//一个 double ,一个 Int 和
         * 4) calculate(int n1, int n2,int n3)//三个 int 的和
         */
        MyCalculator c = new MyCalculator();
        System.out.println(c.calculate(1,2));
        System.out.println(c.calculate(1,2.1));
        System.out.println(c.calculate(1.1,2));
        System.out.println(c.calculate(1,2,3));
    }
}

class MyCalculator{
    public int calculate(int n1, int n2){
        return n1+n2;
    }
    //方法名不同不构成重载
    public int calculate2(int n1, int n2,double d1){
        return n1+n2;
    }
    //没有构成方法重载, 仍然是错误的，因为是方法的重复定义
    // public void calculate(int n1, int n2) {
    // System.out.println("calculate(int n1, int n2) 被调用");
    // intres= n1+n2;
    // }
    public double calculate(int n1, double n2){
        return n1+n2;
    }
    public double calculate(double n1, int n2){
        return n1+n2;
    }
    public int calculate(int n1, int n2, int n3){
        return n1+n2+n3;
    }
}